﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyOpenGame.Entity
{
    public class Player
    {
        private int _gold;
        private string _name;

        public Player(string name)
        {
            if (name == null)
            {
                throw new NullReferenceException("Null in player name");
            }

            _name = name;
            _gold = 50;
        }

        public void AddGold(int gold)
        {
            lock (this)
            {
                _gold += gold;
            }
        }

        public int GetGold()
        {
            lock (this)
            {
                return _gold;
            }
        }

        public void SetName(string name)
        {
            lock (this)
            {
                _name = name;
            }
        }

        public string GetName()
        {
            lock (this)
            {
                return _name;
            }
        }

        public bool Buy(int price)
        {
            bool canBuy = false;
            if (_gold >= price)
            {
                _gold -= price;
                canBuy = true;
            }
            return canBuy;
        }

    }
}
